<?php

namespace app\common\service;

use app\common\exception\MiException;
use app\common\service\traits\InstanceTrait;
use app\model\NoticeTpl;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class CommonNoticeTplService
{

    use InstanceTrait;

    /**
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function getSmsCode(int $siteId): NoticeTpl
    {
        $info = NoticeTpl::where('site_id', $siteId)->where('key', 'sms_code')->find();
        if (!$info){
            throw new MiException("短信验证码模板未设置");
        }
        if ($info->sms_status != 1){
            throw new MiException("短信验证码模板未开启");
        }
        return $info;
    }
}
